﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace WinSilver
{
    static class FileHelper
    {
        public static List<string> GetFilesRecursive(string initialDirectory)
        {
            // Store results in the file results list.
            List<string> result = new List<string>();

            // Store a stack of our directories.
            Stack<string> stack = new Stack<string>();

            // Add initial directory.
            stack.Push(initialDirectory);

            // Continue while there are directories to process
            while (stack.Count > 0)
            {
                // Get top directory
                string dir = stack.Pop();

                try
                {
                    // Add all files at this directory to the result List.
                    result.AddRange(Directory.GetFiles(dir, "*.lnk"));
                    result.AddRange(Directory.GetFiles(dir, "*.appref-ms"));

                    // Add all directories at this directory.
                    foreach (string dn in Directory.GetDirectories(dir))
                    {
                        stack.Push(dn);
                    }
                }
                catch
                {
                    // Could not open the directory
                }
            }
            return result;
        }
    }
}
